import React from 'react';
import { useStaticQuery, graphql } from 'gatsby';
import { Helmet } from 'react-helmet';

export default function Seo({ title, description, meta, lang }) {
  const { site } = useStaticQuery(graphql`
    query {
      site {
        siteMetadata {
          title
          description
        }
      }
    }
  `);
  console.log('SEO site :', site);

  const metaDescription = description || site.siteMetadata.description;

  return (
    <Helmet
      htmlAttributes={{ lang }}
      title={title}
      titleTemplate={`%s | ${site.siteMetadata.title}`}
      meta={[{ name: 'description', content: metaDescription }].concat(meta)}
    />
  );
}

// 默认值
Seo.defaultProps = {
  description: 'study React SSG Gatsby and Strapi',
  meta: [],
  lang: 'en',
};
